package com.ztgf.order.api.client.purchase;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.utils.DateUtils;
import com.ztgf.common.utils.ExcelUtils;
import com.ztgf.order.models.bo.purchase.PurchaseCommodityBargainSaveBO;
import com.ztgf.order.models.bo.purchase.PurchaseInfoBuyBO;
import com.ztgf.order.models.bo.purchase.PurchaseInfoHomeBO;
import com.ztgf.order.models.bo.purchase.PurchaseInfoSellBO;
import com.ztgf.order.models.service.purchase.IPurchaseInfoService;
import com.ztgf.order.models.vo.purchase.PurchaseCommodityBargainVO;
import com.ztgf.order.models.vo.purchase.PurchaseInfoExportVO;
import com.ztgf.order.models.vo.purchase.PurchaseInfoVO;
import com.ztgf.sys.models.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 采购信息表控制器
 *
 * @author mxli
 * @Date 2021-05-17 10:15:52
 */

@RestController
@RequestMapping("/api/purchaseInfo")
@Slf4j
@Api(value = "PurchaseInfoApiController",tags = "采购信息表Api接口")
public class PurchaseInfoApiController {

    @DubboReference
    private IPurchaseInfoService purchaseInfoService;

    @DubboReference
    private ISysConfigService sysConfigService;


    @ApiOperation(value = "买家查询报价列表",notes = "买家查询报价列表")
    @PostMapping("/queryBuyPageList")
    public Result<Page<PurchaseInfoVO>> queryBuyPageList(PurchaseInfoBuyBO bo){
        return purchaseInfoService.queryBuyPageList(bo);
    }

    @PostMapping("/getBuy")
    @ApiOperation(value = "根据id查看买家详情",notes = "根据id查看买家详情")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<PurchaseInfoVO> getBuy(Long id){
        return  purchaseInfoService.getBuy(id);
    }

    @ApiOperation(value = "卖家查询报价列表",notes = "卖家查询报价列表")
    @PostMapping("/querySellPageList")
    public Result<Page<PurchaseInfoVO>> querySellPageList(PurchaseInfoSellBO bo){
        return purchaseInfoService.querySellPageList(bo);
    }

    @PostMapping("/getSell")
    @ApiOperation(value = "根据id查看卖家详情",notes = "根据id查看卖家详情")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<PurchaseInfoVO> getSell(Long id){
        return  purchaseInfoService.getSell(id);
    }

    @ApiOperation(value = "首页查询报价列表",notes = "首页查询报价列表")
    @PostMapping("/queryHomePageList")
    public Result<Page<PurchaseInfoVO>> queryHomePageList(PurchaseInfoHomeBO bo){
        return purchaseInfoService.queryHomePageList(bo);
    }

    @PostMapping("/getHome")
    @ApiOperation(value = "根据id查看首页详情",notes = "根据id查看首页详情")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<PurchaseInfoVO> getHome(Long id){
        return  purchaseInfoService.getHome(id);
    }

    @PostMapping("/saveSellBargain")
    @ApiOperation(value = "卖家报价",notes = "卖家报价")
    public Result saveSellBargain(PurchaseCommodityBargainSaveBO saveBO){
        return  purchaseInfoService.saveSellBargain(saveBO);
    }

    @PostMapping("/saveSellOldBargain")
    @ApiOperation(value = "卖家维持原价",notes = "卖家维持原价")
    public Result saveSellBargainOld(Long purchaseCommodityBargainId){
        return  purchaseInfoService.saveSellBargainOld(purchaseCommodityBargainId);
    }

    @PostMapping("/saveSellAcceptBargain")
    @ApiOperation(value = "卖家接受议价",notes = "卖家接受议价")
    public Result saveSellAcceptBargain(Long purchaseCommodityBargainId){
        return  purchaseInfoService.saveSellAcceptBargain(purchaseCommodityBargainId);
    }

    @PostMapping("/saveBuyBargain")
    @ApiOperation(value = "买家议价",notes = "买家议价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "purchaseCommodityBargainId",value = "报价商品主键id",required = true,paramType = "query", dataType = "Long")
            ,@ApiImplicitParam(name = "price",value = "价格，2位小数",required = true,paramType = "query", dataType = "BigDecimal")
    })
    public Result saveBuyBargain(Long purchaseCommodityBargainId, BigDecimal price){
        return  purchaseInfoService.saveBuyBargain(purchaseCommodityBargainId, price);
    }

    @PostMapping("/saveBuyRefuseBargain")
    @ApiOperation(value = "买家拒绝报价",notes = "买家拒绝报价")
    @ApiImplicitParam(name = "purchaseCommodityBargainIds", value = "报价商品ids:以逗号隔开", required = true, paramType = "query", dataType = "String")
    public Result saveBuyRefuseBargain(String purchaseCommodityBargainIds){
        return  purchaseInfoService.saveBuyRefuseBargain(purchaseCommodityBargainIds);
    }

    @PostMapping("/savePlatBargain")
    @ApiOperation(value = "申请平台报价",notes = "申请平台报价")
    @ApiImplicitParam(name = "platBargain", value = "格式：[{'purchaseCommodityBargainId':1,'price': 100.55},{'purchaseCommodityBargainId':2,'price': 200.55}]", required = true, paramType = "query", dataType = "String")
    public Result savePlatBargain(String platBargain){
        return purchaseInfoService.savePlatBargain(platBargain);
    }

    @PostMapping("/cancelBargain")
    @ApiOperation(value = "取消报价",notes = "取消报价")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "ids,以逗号分隔",required = true,paramType = "query", dataType = "String")
            ,@ApiImplicitParam(name = "canceType",value = "参照数据字典类型",required = true,paramType = "query", dataType = "Integer")
            ,@ApiImplicitParam(name = "cancelDescription",value = "取消说明",required = true,paramType = "query", dataType = "String")
    })
    public Result cancelBargain(String ids, Integer cancelType, String cancelDescription){
        return  purchaseInfoService.saveCanceBargain(ids, cancelType, cancelDescription);
    }

    @PostMapping("/saveShoppingCart")
    @ApiOperation(value = "加入购物车",notes = "加入购物车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "purchaseCommodityBargainIds",value = "报价商品ids,以逗号分隔",required = true,paramType = "query", dataType = "String")
    })
    public Result saveShoppingCart(String purchaseCommodityBargainIds){
        return  purchaseInfoService.saveShoppingCart(purchaseCommodityBargainIds);
    }

    @PostMapping("/saveBuy")
    @ApiOperation(value = "立即购买",notes = "立即购买")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "purchaseCommodityBargainId",value = "报价商品id",required = true,paramType = "query", dataType = "Long")
    })
    public Result saveBuy(Long purchaseCommodityBargainId){
        return  purchaseInfoService.saveBuy(purchaseCommodityBargainId);
    }


    @PostMapping("/getCommodityBargain")
    @ApiOperation(value = "根据id报价商品详情",notes = "根据id报价商品详情")
    @ApiImplicitParam(name = "id",value = "报价商品表主键id",required = true,paramType = "query", dataType = "Long")
    public Result<PurchaseCommodityBargainVO> getCommodityBargain(Long id,Long brandId,Long shopId){
        return  purchaseInfoService.getCommodityBargain(id,brandId,shopId);
    }


    @PostMapping("/getPurchaseInfo")
    @ApiOperation(value = "查询询价点信息（相似商品）",notes = "查询询价点信息（相似商品）")
    @ApiImplicitParam(name = "id",value = "报价单主键id",required = true,paramType = "query", dataType = "Long")
    public Result<PurchaseInfoVO> getPurchaseInfo(Long id){
        return  purchaseInfoService.getPurchaseInfo(id);
    }

    @ApiOperation(value = "导出买家报价单列表",notes = "导出买家报价单列表")
    @PostMapping("/exportBuyList")
    public void exportBuyList (HttpServletResponse response, PurchaseInfoBuyBO bo){
        List<PurchaseInfoExportVO> purchaseInfoExportVOS = purchaseInfoService.queryExportBuyList (bo);
        ExcelUtils.exportExcel(purchaseInfoExportVOS,"询价单列表","询价单列表", PurchaseInfoExportVO.class,"询价单列表"+ DateUtils.dateToStr(new Date (), DateUtils.DATE_FORMAT_DATESHORTDAY) +".xlsx",response);
    }

    @ApiOperation(value = "导出卖家报价单列表",notes = "导出卖家报价单列表")
    @PostMapping("/exportSellList")
    public void exportSellList(HttpServletResponse response,PurchaseInfoSellBO bo){
        List<PurchaseInfoExportVO> purchaseInfoExportVOS = purchaseInfoService.queryExportSellList (bo);
        ExcelUtils.exportExcel(purchaseInfoExportVOS,"询价单列表","询价单列表", PurchaseInfoExportVO.class,"询价单列表"+ DateUtils.dateToStr(new Date (), DateUtils.DATE_FORMAT_DATESHORTDAY) +".xlsx",response);
    }



}
